/*
 * File:   main.c
 * Author: Chris Matheson
 *
 * Created on 15 July 2011, 15:40
 */
#include <stdio.h>
#include <p24F04KA201.h>

_FOSC(FOSC_INTOSC & CLKOUTEN_ON & WDTE_OFF);
_FOSC(LVP_OFF );
// INTOSC oscillator: I/O function on CLKIN pin
// CLKOUTEN function is enabled on the CLKOUT pin
// WDTE off for debug purposes.
// LVP low voltage programing? cant remember why this is off

int main(void) {
    OSCCONbits.IRCF = 0b1111;
    TRISA = 0x00; //port A as outputs
    PORTA = 0x00;
    PORTAbits.RA4 = 1;
    TRISB = 0x00; //port A as outputs
    PORTB = 0x00;
    //setupPWM();
    while(1){
        NOP();
        NOP();
        NOP();
    }
    //TODO Global run time limit
    //TODO start global Timer

    //FEATURE battery meter
    
    //TODO PWM of LED output
    return 0;
}



int setupPWM(void){
    TRISB = 0xFF;   //Disable output drivers
    PR4 = 0x80;   //Set PWM length
    CCP4CON = 0xFF;  //Set CCPM for PWM mode);   //return zero for failed setup
    //C4TSEL = 0x1;   //CCP4 based on Timer4
    CCPR4L = 0x0F;  //Set Duty Cycle
    //PIR3.TMR4IF = 0;//clear interupt flag
    //T2CON.TMR4ON = 1;//Start Timer
    
    return(0);
}


